from django.shortcuts import render
from django_filters import views
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response

from user import models
from user import serializers
# Create your views here.
class UserViewSet(viewsets.ModelViewSet):
    queryset = models.User.objects.all()
    serializer_class = serializers.Userr
    @action(detail=False, methods=["POST"])
    def get_user(self, request):
#         手机号是否存在，存在密码是否相同
        data=models.User.objects.filter(phone=request.data.get('phone')).first()
        if data:
            if data.password==request.data.get('password'):
                return Response({'code':200,'msg':'登录成功'})
            else:
                return Response({'code':400,'msg':'密码错误'})
        else:
            return Response({'code':202,'msg':'手机号不存在'})

